package lab03.test12;

import java.sql.*;

/**
 * Created by 123 on 2017/12/11.
 */
public class Test {
    public static void main(String[] args) {
        Connection connection = null;
        Statement statement = null;
        ResultSet resultSet = null;

        String sql = "select * from t_users";
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            connection = DriverManager.getConnection(
                    "jdbc:mysql://localhost:3306/java_2017?serverTimezone=UTC",
                    "root",
                    "123456"
            );

            statement = connection.createStatement();

            resultSet = statement.executeQuery(sql);//执行查询并返回结果集

            while (resultSet.next()) {//通过next来索引：判断是否有下一个记录
                int id = resultSet.getInt(1);//方法：int java.sql.ResultSet.getInt(String columnLabel) throws SQLException
                String usrname = resultSet.getString(2);
                String password = resultSet.getString(3);
                long registerdatetime = resultSet.getLong(4);
                System.out.println("id=" + id + "usename=" + usrname + "password" + password + "registerdatetime" + registerdatetime);
            }

//            System.out.println(resultSet);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
